Hi
I tried several combinations just need to prompt user to enter the domain user account that need to be added as a local administrator on the current PC and let them type the username
and need to hardcode the domain admin account in the vbs script can we do this. I tried this but it did not work for me
Option Explicit
Dim domainAdmin, domainAdminPassword, domainUserName, group, groupMember
Dim objNetwork, objGroup, objUser
' Prompt user for domain user name
domainUserName = InputBox("Enter the domain user name to add to the local Administrators group:", "Add User to Local Administrators Group")
' Hard-code domain admin credentials
domainAdmin = ""
domainAdminPassword = ""
' Get a reference to the local Administrators group
Set objGroup = GetObject("WinNT://./Administrators")
' Get a reference to the user to add to the group
Set objUser = GetObject("WinNT://" & domainUserName)
' Add the user to the local Administrators group
On Error Resume Next
objGroup.Add(objUser.ADsPath)
If Err.Number = 0 Then
' Display success message
MsgBox "User " & domainUserName & " has been added to the local Administrators group.", vbInformation, "User Added"
Else
' Display error message
MsgBox "Failed to add user " & domainUserName & " to the local Administrators group. Error: " & Err.Description, vbCritical, "Error Adding User"
End If
' Clean up
Set objUser = Nothing
Set objGroup = Nothing
|